﻿using System.Collections.Generic;
using DomainModel.Tests.Fakes;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;

namespace DomainModel.Tests
{
    internal class TestConfigurer
    {
        internal void Configure()
        {
            // Initialize Service location mechanism
            var container = new UnityContainer();
            var unityServiceLocator = new UnityServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => unityServiceLocator);
            
            // Register repositories
            container.RegisterType<ISignalementRepository, FakeSignalementRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IObjetPatrimonialRepository, FakeObjetPatrimonialRepository>(new ContainerControlledLifetimeManager());
            container.RegisterType<IPanneRepository, FakePanneRepository>(new ContainerControlledLifetimeManager());

            //// Fill the database with fake datas
            //var signalementRepository = container.Resolve<ISignalementRepository>();
            //var objetPatrimonialRepository = container.Resolve<IObjetPatrimonialRepository>();
            //var panneRepository = container.Resolve<IPanneRepository>();

            //CreatePannes(panneRepository);
            //CreateObjetPatromanial(objetPatrimonialRepository);
        }

        private void CreatePannes(IPanneRepository panneRepository)
        {
            var pannes = new List<Panne>()
                           {
                               new Panne("LMP-CA", "Lampe cassée", PanneSeverity.Moderate) { Id = 1 },
                               new Panne("SUP-PL", "Support légèrement plié", PanneSeverity.Moderate) { Id = 2 },
                               new Panne("SUP-AR", "Support arraché du sol", PanneSeverity.Serious) { Id = 3 },
                               new Panne("CBL-SE","Cable d'alimentation sectionné", PanneSeverity.Serious) { Id = 4 }
                           };

            pannes.ForEach(panneRepository.Add);
        }

        private void CreateObjetPatromanial(IObjetPatrimonialRepository objetPatrimonialRepository)
        {
            var objetPatrimonials = new List<ObjetPatrimonial>()
                           {
                               new ObjetPatrimonial("CAN-01","Candélabre") { Id = 1, Age = 3, Town = "Marseille", State = ObjetPatrimonialState.FullyOperational},
                               new ObjetPatrimonial("FRO-01","Feu rouge") { Id = 2, Age = 15, Town = "Marseille", State = ObjetPatrimonialState.PartiallyOperational},
                               new ObjetPatrimonial("RAD-01","Radar") {Id = 3, Age = 7, Town = "Paris", State = ObjetPatrimonialState.FullyOperational},
                               new ObjetPatrimonial("CAN-02","Lampadaire") {Id = 4, Age = 17, Town = "Paris", State = ObjetPatrimonialState.PartiallyOperational},
                               new ObjetPatrimonial("FRO-02","Panneau publicitaire") { Id = 5, Age = 1, Town = "Aix-en-Provence", State = ObjetPatrimonialState.FullyOperational}
                           };

            objetPatrimonials.ForEach(objetPatrimonialRepository.Add);
        }
    }
}
